#include <fcntl.h> 
#include <unistd.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <cctype>
#include <string>
#include <cstdio>

using namespace std;

struct FastReader 
{
    int fd;
    struct stat meta;
    size_t size;
    char *start, *end;
    char *pos;

    bool fastOpen(const char *path) 
    {
        fd = open(path, O_RDONLY);
        fstat(fd, &meta);
        size = meta.st_size;
        start = (char*)mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
        if (start == MAP_FAILED)
            return false;
        else 
        {
            pos = start;
            end = start + size;
            return true;
        }
    }

    void fastClose()
    {
        munmap(start, size);
        close(fd);
    }

    inline void skipLine()
    {
        while (*pos != '\n') 
            ++ pos;
        ++ pos;
    }

    inline bool hasNext() const
    {
        return (pos < end);
    }

    inline int getInt()
    {
        int res = 0;
        while (isdigit(*pos)) 
        {
            res = res * 10 + ((*pos) - '0');
            ++ pos;
        }
        if ((*pos) == '|')
            ++ pos;
        return res;
    }

    inline string getString()
    {
        string res = "";
        while ((*pos) != '|' && (*pos) != '\n') 
        {
            res += (*pos);
            ++ pos;
        }
        if ((*pos) == '|')
            ++ pos;
        return res;
    }
};
